package com.letao.server.controller;

import com.letao.server.dto.Result;
import com.letao.server.service.ISalesOnMonthService;
import com.letao.server.service.ISalesOnSeasonService;
import com.letao.server.service.ISalesOnWeekService;
import com.letao.server.service.IStatisticsService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;

@RestController
@RequestMapping("/statistics")
public class StatisticsController {
    @Resource
    private ISalesOnWeekService salesOnWeekService;
    @Resource
    private ISalesOnMonthService salesOnMonthService;
    @Resource
    private ISalesOnSeasonService salesOnSeasonService;
    @Resource
    private IStatisticsService statisticsService;

    /*
      用户相关信息
      筛选条件：查询时间范围（按创建时间）
      返回数据：每一天的用户创建数，用户总数，各个性别对应人数，用户购买订单金额排序，

      商品相关信息
      筛选条件：
      返回数据：商品数，销量排序，最新上架的几个商品，按好评排序的商品

      订单相关信息
      筛选条件：时间
      返回数据：订单数，订单金额排序排序，订单取消数，正常订单数，秒杀订单数

    */
    @GetMapping("/user")
    private Result user(@RequestParam(required = false) LocalDateTime begin,
                        @RequestParam(required = false) LocalDateTime end) {
        return statisticsService.userQuery(begin, end);
    }

    @GetMapping("/product")
    private Result product(
            @RequestParam(required = false) Long oneCategoryId
    ) {
        return statisticsService.productQuery(oneCategoryId);
    }

    @GetMapping("/order")
    private Result order(@RequestParam(defaultValue = "0") Integer sevenDays) {
        return statisticsService.orderQuery(sevenDays);
    }
}
